package wfc.userServlet;


import wfc.entity.Dish;
import wfc.service.DishService;
import wfc.service.serviceImpl.DishServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/myDishServlet")
public class myDishServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        //根据用户名查找用户菜品
        DishService dishService = new DishServiceImpl();
        List<Dish> dishList = dishService.selectByuname(username);
        //session存入用户菜单
        HttpSession session = req.getSession();
        session.setAttribute("dishList",dishList);
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html; charset=utf-8");
        PrintWriter writer = resp.getWriter();
        String mess="";
        if(!"null".equals(dishList) ){
            //session存用户信息
            mess="1";
        }else {
            mess="0";
        }
        writer.println(mess);
        writer.flush();
        writer.close();

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("这是post请求");
    }
}
